package com.xoms.front.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.xoms.front.controller.res.*;
import com.xoms.front.controller.res.bean.*;
import com.xoms.front.controller.springmvc.req.*;

/**
 * 订单相关接口
 **/
@Controller
@RequestMapping(value = "/order", produces = "application/json")
public class SOrderController {
	@Autowired
	com.xoms.front.controller.OrderController orderController;

	/**
	 * 卖品下单
	 **/
	@RequestMapping("/v1/putProOrder")
	@ResponseBody
	public ObjectResult<ROrderBean> putProOrder(@Validated GetPutOrderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderBean> res = new ObjectResult<ROrderBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.putProOrder(param, request, response);
	}

	/**
	 * 订单列表
	 **/
	@RequestMapping("/v1/orderList")
	@ResponseBody
	public ListResult<ROrderListBean> orderList(@Validated GetOrderListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<ROrderListBean> res = new ListResult<ROrderListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.orderList(param, request, response);
	}
}
